{layout name="../common/master"/}

<script src="__PUBLIC__/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/uploadify/uploadify.css">
<style>
    .repay_period{
        display: none;
    }
</style>

<div id="right">
    <h4 style="border-bottom: 1px solid #ccc;padding-bottom: 3px">添加新产品</h4>
    <div id="app">
        <form action="javascript:;" method="post" role="form" class="col-lg-6">
            <div class="form-group">
                <label for="">产品名称</label>
                <input type="text" class="form-control" required  name="name"  placeholder="请输入产品名称">
            </div>
            <div class="form-group">
                <label for="">产品后台名称</label>
                <input type="text" class="form-control" required  name="admin_name"  placeholder="请输入产品名称">
            </div>
            <div class="form-group">
                <label for="">产品价格</label>
                <input type="text" class="form-control" required name="price"  placeholder="请输入产品价格">
            </div>
            <div class="form-group">
                <label for="">产品类型</label>
                <select name="sort" id="couponType" class="form-control">
                    <option value=""> -- Select One --</option>
                    <option value="100"> EWI</option>
                    <option value="1"> 0307</option>
                    <option value="2"> 0314</option>
                    <option value="3"> 0607</option>
                    <option value="4"> 0614</option>
                    <option value="5"> 1007</option>
                    <option value="6"> 1015</option>
                </select>
            </div>
            <div class="form-group repay_period">
                <label for="">分期期数</label>
                <input type="text" class="form-control"  name="repay_count"  placeholder="请输入分期期数">
            </div>
            <div class="form-group repay_period" id="product_configuration" style="border: 1px solid red">
                <button type="button" id="addPeriod" class="btn btn-info" style="margin-left: 100px">+</button>
                <div style="border: 1px solid #CCCCCC;margin: 8px 8px" class="ewiperiod">
                    <label for="">周期</label>
                    <br/>
                    <input type="text" class="form-control"  name="repay_period[]"  placeholder="请输入还款周期">

                    <label for="">还款金额</label>
                    <br/>
                    <input type="text" class="form-control"  name="repay_money[]"  placeholder="请输入还款金额">
                </div>
            </div>
            <div class="form-group">
                <label for="">权重</label>
                <input type="text" class="form-control"  name="plantform"  placeholder="请输入权重">
            </div>
            <div class="form-group">
                <label for="">是否上架</label>

                <div class="radio">
                    <label>
                        <input type="radio" name="is_valid" value="1" checked="checked">
                        上架
                    </label>
                    <label>
                        <input type="radio" name="is_valid" value="0">
                        不上架
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label for="">产品年利率</label>
                <input type="text" class="form-control" name="product_rate"  placeholder="请输入产品年利率">
            </div>
            <div class="form-group">
                <label for="">逾期费率</label>
                <input type="text" class="form-control"  name="overdue_rate"  placeholder="请输入逾期费率">
            </div>
            <div class="form-group">
                <label for="">信审费用</label>
                <input type="text" class="form-control"  name="info_check_fee"  placeholder="请输入信审费用">
            </div>
            <div class="form-group">
                <label for="">管理费用</label>
                <input type="text" class="form-control"  name="manage_fee"  placeholder="请输入管理费用">
            </div>
            <div class="form-group">
                <label for="">convenience 费用</label>
                <input type="text" class="form-control"  name="convenience_fee"  placeholder="请输入convenience费用">
            </div>
            <div class="form-group">
                <label for="">分享URL</label>
                <input type="text" class="form-control"  name="share_url"  placeholder="请输入分享URL">
            </div>
            <div class="form-group">
                <label for="">产品时长</label>
                <input type="text" class="form-control"  name="period"  placeholder="产品时长">
            </div>
            <div class="form-group">
                <label for="">最高额度</label>
                <input type="text" class="form-control"  name="max_loan"  placeholder="最高额度">
            </div>
            <div class="form-group">
                <label for="">备注</label>
                <br/>
                <textarea id="uremark" name="comment"  cols="10" rows="3"></textarea>
            </div>
            <button type="submit" id="form_submit" class="btn btn-primary">提交</button>
        </form>
    </div>
</div>
<script>
    $("#couponType").change(function(){
        var value=$(this).val();
        if(value == 100){
            $(".repay_period").show();
        }else{
            $(".repay_period").hide();
        }
    })
    $("#addPeriod").click(function(){
//        var ewiPeriod=$(".ewiperiod").clone();
        var ewiPeriodLength=$(".ewiperiod").length;
        var ewiRepay=`<div style="border: 1px solid #CCCCCC;margin: 8px 8px" class="ewiperiod">
                <label for="">周期</label>
                <br/>
                <input type="text" class="form-control"  name="repay_period[]"  placeholder="请输入还款周期">

                <label for="">还款金额</label>
                <br/>
                <input type="text" class="form-control"  name="repay_money[]"  placeholder="请输入还款金额">
                </div>`;
        if(ewiPeriodLength > 3){
            layer.alert("总周期不能超过4");
        }else{
            $("#product_configuration").append(ewiRepay);
        }
    })
    $("#form_submit").click(function () {
        var data=$('form').serialize();
        $.post("{:URL('home/Product/productAdd')}",data,function(res){
           if(res.code == 0){
               layer.msg(res.msg);
               location.href="{:URL('home/Product/productList',['type'=>'list'])}";
           }else{
               layer.msg(res.data,function(){});
           }
        })
    })
</script>

